package com.hyc.message;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;


@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class RpcResponse implements Serializable {
    private String requestId;
    //状态信息 http
    private int code;
    private MessageType type;

    private String message;
    //具体数据
    private Object data;

    //更新：加入传输数据的类型，以便在自定义序列化器中解析
    private Class<?> dataType;

    //构造成功信息
    public static RpcResponse success(Object data) {
        return RpcResponse.builder().code(200).data(data).build();
    }

    public static RpcResponse nettySuccess(String requestId, Object data, Class<?> dataType) {
        return RpcResponse.builder().requestId(requestId).type(MessageType.RESPONSE).code(200).data(data).dataType(dataType).build();
    }


    public static RpcResponse fail(String requestId, String msg) {
        return RpcResponse.builder().requestId(requestId).type(MessageType.RESPONSE).code(500).message(msg).build();
    }
}

